#ifndef _TOOL_SETPARA_H_
#define _TOOL_SETPARA_H_

#ifdef __cplusplus
 extern "C" {
#endif

#include "includes.h"

//#define USE_SPIFLASH
	 
#define U32_BUFSIZE 32 //32位发送数组中元素个数
#define W25Qxx_BUFSIZE 32*4
#define W25QxxAddress0 0
#define W25QxxAddress1 512

struct Parameter_User_Struct
{
	unsigned char Begin;//帧头
	//键鼠
	uint16_t SPEED1;//一档速度(0~660)
	uint16_t SPEED2;//二档速度(0~660)
	float PITCHWEIGHT;//PITCH电机调节速度（越大越快）
	float YAWWEIGHT[2];//YAW电机调节速度（越大越快）

	//遥控
	float DR_SPEED;//速度（越大越快）
	float PitchScale;//PITCH电机调节速度（越小越快）
	float YawScale;//YAW电机调节速度（越小越快）

	float motor;
	unsigned char End;//帧尾
};

union Parameter_User_Union
{
	struct Parameter_User_Struct data;
	u32 FlashData[U32_BUFSIZE];
	u8 W25QXXData[W25Qxx_BUFSIZE];
};

struct Parameter_Operater_Struct
{
	unsigned char Begin;//帧头
    float PITCH_Encoder_Mid;//PITCH电机码盘值
    float PITCH_Encoder_Up;//PITCH电机码盘值
    float PITCH_Encoder_Dowm;//PITCH电机码盘值
    float YAW_Encoder_Mid;//YAW电机码盘值
	  float PITCH_6050_Offset;//6050角速度offset
    float YAW_6050_Offset;//6050角速度offset
	s16 RealShootSpeed1;//摩擦轮1速度
	s16 RealShootSpeed2;//摩擦轮2速度
	s16 RealShootFreq;//射频
	float Rune_Yaw_c;
	float Rune_Yaw_a;
	float Rune_Yaw_b;
	float Rune_Pitch_a;
	float Rune_Pitch_b;
	unsigned char End;//帧尾
};

union Parameter_Operater_Union
{
	struct Parameter_Operater_Struct data;
	u32 FlashData[U32_BUFSIZE];
	u8 W25QXXData[W25Qxx_BUFSIZE];
};

typedef __packed struct {
	u8 buff[7];
}dev_version;
typedef __packed struct{
	dev_version main_control;
	dev_version usart_can;
	dev_version gyroscope;
	dev_version statusdisplay;
	dev_version driver[4];
}version_info;

void InitParameter_User(void);
void GetParameter_User(void);
void SetParameter_User(void);
void CheckParameter_User(void);

void InitParameter_Operater(void);
void GetParameter_Operater(void);
void SetParameter_Operater(void);
void CheckParameter_Operater(void);

void Tool_SetPara_Init(void);

u8 GetParaFlag(void);
void SetParaFlag(u8 _pFlag);
void SetPara_DR(float _DR_SPEED,float _PitchScale,float _YawScale,float CARFRAMEWEIGHT);
void SetPara_KM(float SPEED1,float SPEED2,float PITCHWEIGHT,float YAWWEIGHT1,float YAWWEIGHT2,float CARFRAMEWEIGHT);
void SetPara_Operater(float mode);
void ParaSetting(float _pFlag);
void ESCSetPara(float _mESC_PWM_speed,float _mESC_PWM_volate,float _mFreq);

#ifdef  _TOOL_SETPARA_GLOBALS
#define _TOOL_SETPARA_EXT     
#else   
#define _TOOL_SETPARA_EXT    extern  
#endif	

_TOOL_SETPARA_EXT union Parameter_Operater_Union Parameter_Operater;
_TOOL_SETPARA_EXT union Parameter_User_Union Parameter_User;
#ifdef __cplusplus
}
#endif

#endif

